package me.sauce.folkpocket48.home

import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import io.reactivex.subscribers.DisposableSubscriber
import kotlinx.android.synthetic.main.fragment_home.*
import me.sauce.folkpocket48.R
import me.sauce.folkpocket48.data.DataResponse
import me.sauce.folkpocket48.data.local.database.entity.Member
import me.sauce.folkpocket48.databinding.FragmentHomeBinding

/**
 * @author sauceWu .
 * @since 2017/12/21 11:05
 */

class LifeActivity : AppCompatActivity() {

    var db: FragmentHomeBinding? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        db = DataBindingUtil.setContentView(this, R.layout.fragment_home)
        var lm = LifeModule(this)

startActivity()
        setViewHole(HomeViewModule("1"))


        bt_db.setOnClickListener {
            Flowable.just(Member(System.currentTimeMillis().toString() + ""))
                    .subscribeOn(Schedulers.io())
                    .map { DataResponse.data.testDao().insertAll(it) }
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(object : DisposableSubscriber<LongArray>() {
                        override fun onNext(longs: LongArray) {
                            Toast.makeText(this@LifeActivity, longs[0].toString(), Toast.LENGTH_SHORT).show()
                        }

                        override fun onError(t: Throwable) {

                        }

                        override fun onComplete() {

                        }
                    })
        }

    }

    fun setViewHole(vm: HomeViewModule) {
        db?.vm = vm
    }
}
